require(['../config/requireconfig'],function(config){
	//根据需要添加
	require(['zepto','common/mcommon','common/prodGen'],function($,com,prodGen){
        com.init();
		var pageLogic = new PageLogic($,com,prodGen);
		pageLogic.init();

	});
});
var PageLogic = function($,com,prodGen){
	
	return{
		init:function(){
			var _this =this;
			_this.initData();
		},
		params:function(){
			var vehicleNo = com.utils().urlParam("vehicleNo");
			return {
				vehicleNo:vehicleNo
			};
		},
		initData:function(){
			var _this =this;
			com.ajax({
				url:"/mprodLtTeamList1.json",
				data:_this.params(),
				success:function(res){
					_this.initNav(
						res.data.carlist[0].BRAND_NAME,
						res.data.carlist[0].MODEL_NAME,
						res.data.carlist[0].DISPLACEMENT_L);
					_this.initCondition(res.data.tyreList1);
					prodGen.genPartInfo(res.data.tyreList1,_this.afterSelectPart);
				}
			});
		},
		initNav:function(brandName,modelName,displacementL){
			$("#brandName").text(brandName);
			$("#modelName").text(modelName);
			$("#displacementL").text(displacementL);
		},
		initCondition:function(tyreList){
			var _this = this;
			var options = [];
			$(tyreList).each(function(idx,obj){
				if(idx == 0){
					$(obj.name).each(function(idx1,obj1){
						options.push({name:obj1,values:[]});
					});
				}
				$(obj.value).each(function(idx2,val1){
					options[idx2].values.push(val1);
				})
			});
			var html = "";
			$(options).each(function(idx){
				html += '<li><span>' + this.name + '</span>' + genOptions(idx,this.values) + '</li>';
			});
			$("#subCon").html(html);
			$("#subCon").find("select").on("change",function(){
				_this.getByCondition();
			});
			function genOptions(idx,values){
				var arr = com.utils().uniqueArr(values);
				var tg = 3 - idx;
				var html = "<select tg='" + ("reserve" + tg) + "'><option>全部</option>";
				$(arr).each(function(idx,val){
					html += '<option>' + val + '</option>'
				})
				html += "</select>";
				return html;
			}
		},
		getByCondition:function(){
			var _this = this;
			$(".prd-info").html("");
			var arr = [];
			var cond = _this.params();
			var i = 0;
			$("#subCon").find("select").each(function(){
				var tg = $(this).attr("tg");
				var val = $(this).val();
				if(val == "全部"){
					val = "";
				}
				cond[tg] = val;
				arr[i]= val;
				i++;
			});
			$(".parts-info .tb").find("tbody").find("tr").each(function(){
				var split = arr;
				var tr = $(this);
				var tdArr = $(tr).find("td");
				var len = $(tr).find("td").length;
				var flg = true;
				if(split[3] && !($(tdArr[len-1]).text() == split[3])){
					flg = false;
				}
				if(split[2] && !($(tdArr[len-2]).text() == split[2])){
					flg = false;
				}
				if(split[1] && !($(tdArr[len-3]).text() == split[1])){
					flg = false;
				}
				if(split[0] && !($(tdArr[len-4]).text() == split[0])){
					flg = false;
				}
				if(flg){
					tr.show();
				}else{
					tr.hide();
				}
			});
			// com.ajax({
			// 	url:"/tyreList.json",
			// 	data:cond,
			// 	success:function(res){
			// 		prodGen.genPartInfo(res.data,_this.afterSelectPart);
			// 	}
			// });

		},
		afterSelectPart:function(partNo){
			com.ajax({
				url:"/getPartNumber2.json",
				data:{vehicleNo: partNo},
				success:function(res){
					prodGen.genPrdInfo($(".prd-info"),res.data);
				}
			})
		}
	}
}